package com.hongxin.nw.netty.model.packing.info;

import com.hongxin.nw.netty.utils.FieldPack;
import com.hongxin.nw.netty.values.TypeIdentif;
import lombok.extern.slf4j.Slf4j;

/**
 * @remark A.29 远程功率控制
 * @author: GuoXiaolin
 * @date 2019/5/28 10:05
 * @Version 1.0
 * @Descibe
 */
@Slf4j
public class Csdna1_14 implements IPacking {

    private String co;//1	充电设备编号	压缩BCD码	8Byte	充电设备编号
    private String chargeIdentify;//2	充电接口标识	BIN码	1Byte	充电设备为一桩多充时用来标记接口号，一桩一充时此项为0。多个接口时顺序对每个接口进行编号
    private String kwParam;//3	功率控制参数	BCD码	2Byte	格式：NNN.NNNN.N：单位为%，限定输出功率为额定输出功率的百分比。
    private String stopTime;//4	限定截止时间	BIN码	7Byte	CP56Time2a格式: 限定截止时间，超出此时间充电设备自动取消限制。

    public Csdna1_14 setCo(String co) {
        this.co = FieldPack.caseToBCD(co, TypeIdentif.BYTE_CO.getByteLength());
        return this;
    }

    public Csdna1_14 setChargeIdentify(String chargeIdentify) {
        this.chargeIdentify = FieldPack.caseToBin(chargeIdentify, TypeIdentif.BYTE_CHARGE_INTERFACE_IDENTIFY.getByteLength());
        return this;
    }

    public Csdna1_14 setKwParam(double kwParam) {
        this.kwParam = FieldPack.decimalToHex(kwParam, 3, TypeIdentif.BYTE_KW_Param.getByteLength());
        return this;
    }
    public Csdna1_14 setStopTime(String stopTime) {
        this.stopTime = FieldPack.caseTime(stopTime);
        return this;
    }

    @Override
    public String packing() {
        return this.co +
                this.chargeIdentify +
                this.kwParam +
                this.stopTime;
    }

    @Override
    public String toString() {
        return "Csdna1_3{" +
                "co='" + co + '\'' +
                ", chargeIdentify='" + chargeIdentify + '\'' +
                ", kwParam='" + kwParam + '\'' +
                ", stopTime='" + stopTime + '\'' +
                '}';
    }
}
